package com.yingyi.basic.intercepter.config;

import com.yingyi.basic.intercepter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  使用配置类来配置拦截器，相当于之前使用xml配置拦截器
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor) //添加拦截器
                //拦截所有的请求
                .addPathPatterns("/**")
                //放行资源
                //放行登录相关的请求
                .excludePathPatterns("/login/**")
                //放行注册相关的请求
                .excludePathPatterns("/user/register/**", "/verifyCode/**")
                .excludePathPatterns("/shop/settlement", "/shop/active/**" ,"/fastdfs")
                //放行swagger
                .excludePathPatterns("/swagger-resources/**", "/webjars/**",
                        "/v2/**", "/swagger-ui.html/**");
                //如果写了邮箱激活还要放行邮箱
    }
}